package net.neptech.model.vo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.Accessors;
import net.neptech.model.appointment.ClnicStaff;
import net.neptech.model.schedule.ScheShift;
import net.neptech.model.schedule.Schedule;
import net.neptech.utils.DateUtils;

import java.sql.Time;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.util.Date;

@Data
@NoArgsConstructor
@Accessors(chain = true)

public class ScheduleToClnic extends ClnicStaff {

    public ScheduleToClnic(Schedule schedule) {
        ScheShift scheShift = schedule.getScheShift();
        this.setStaffId(schedule.getStaffId());
        Time startTime = scheShift.getStartTime();
        Long deptId = schedule.getDeptId();
        // 处理预约时间：合并 dutyDay 的日期 与 startTime 的时间
        Date dutyDay = schedule.getDutyDay();
        Date merged = DateUtils.mergeDateAndTime(dutyDay, startTime);
       //赋值
        this.setClnicTime(merged);
        this.setTypeId(1);
        this.setDeptId(deptId);
        this.setStatus(statusTo(schedule.getStatus()));
        this.setSlotTotal(30);
        this.setSlotUse(0);
        this.setPeriod(shiftNameToClnicP(scheShift.getShiftName()));
        Date date = new Date();
        this.setCreateAt(date);
        this.setUpdateAt(date);
    }

    /**
     * 排班时间与坐诊时间关系转换
     * @param shiftName
     * @return
     */

    public String shiftNameToClnicP(String shiftName) {
        return switch (shiftName) {
            case "上午坐诊" -> "上午";
            case "下午坐诊" -> "下午";
            default -> "";
        };
    }

    /**
     * 状态转换 排班是1 正常 0 停诊
     * 坐诊是0.正常1.停诊
     * @param status
     * @return
     */

    public Integer statusTo(Integer status) {
        return switch (status) {
            case 1 -> 0;
            default -> 1;
        };
    }
    public String toString() {
        return "ScheduleToClnic{" +
                "staffId=" + this.getStaffId() +
                ", clnicTime=" + this.getClnicTime() +
                ", typeId=" + this.getTypeId() +
                ", deptId=" + this.getDeptId() +
                ", status=" + this.getStatus() +
                ", slotTotal=" + this.getSlotTotal() +
                ", slotUse=" + this.getSlotUse() +
                ", period='" + this.getPeriod() + '\'' +
                '}';
    }
    


}
